class Solution {
public:
    int intersectionSizeTwo(vector<vector<int>>& intervals) {
        
        sort(intervals.begin(),intervals.end(),[&](const vector<int>& p1,const vector<int>& p2){
            if(p1[1]==p2[1]){
                return p1[0]>p2[0];
            }
            return p1[1]<p2[1];
        });
        int nRet=2;
        int maxn1=intervals[0][1],maxn2=intervals[0][1]-1;
        for(int i=1;i<intervals.size();++i){
            int left=intervals[i][0],right=intervals[i][1];
            if(left>maxn1){
                nRet+=2;
                maxn1=right;
                maxn2=right-1;
            }
            else if(left>maxn2){
                nRet+=1;
                maxn2=maxn1;
                maxn1=right; 
            }
        }

        return nRet;
    }
};
